package cn.u313.repository;

import cn.u313.entry.JiLuEntry;
import cn.u313.entry.TestEntry;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

public interface JiLuEntryRepository extends JpaRepository<JiLuEntry, Integer>, JpaSpecificationExecutor<JiLuEntry> {
    @Query(nativeQuery = true,value = "SELECT * FROM `t_yjilu` where id = '89152' ")
    JiLuEntry byQQ(String s);
    @Query(nativeQuery = true,value = "select count(1) from t_yjilu where to_days(time) = to_days(now()) and qq0 = :qq and type=:type ")
    int countByqqAndType(String qq,String type);
    @Query(nativeQuery = true,value = "select count(1) from t_yjilu where to_days(time) = to_days(now()) and qq1 = :qq and type=:type ")
    int countByqq1AndType(String qq,String type);
    @Query(nativeQuery = true,value = "select count(1) from t_yjilu where to_days(time) = to_days(now()) and qq0 = :qq and qq1 =:qq1 and n<>0 and  type=:type ")
    int countQqToQq1(String qq,String qq1,String type);

    @Query(nativeQuery = true,value = "select count(1) from t_yjilu where to_days(time) = to_days(now()) and qq0 = :qq and qq1 =:qq1 and type=:type ")
    int countQqToQq1andType(String qq,String qq1,String type);
    /**
     * 通过用户与奖励类型获取今天是否兑换
     * @param qq
     * @param type
     * @return
     */
    @Query(nativeQuery = true,value = "select count(1) from t_yjilu where to_days(time) = to_days(now()) and qq0 = :qq and type like :type ")
    int countByqqAndTypeLike(String qq, String type);

    @Query(nativeQuery = true,value = "SELECT count(1) FROM `t_yjilu` where `t_yjilu`.`type`=:type and `t_yjilu`.`time` > :time ")
    int getByTimeNumber(String type, String time);
    @Query(nativeQuery = true,value = "select * from t_yjilu where qq0 = :qq and type=:type ")

    JiLuEntry countByqqAndTypeEntry(String qq, String type);
    @Query(nativeQuery = true,value = "SELECT count(1) FROM `t_yjilu` where qq0=:qq and type like '抽福卡%' and time >'2023-01-01'")
    int countByqqAndCard(String qq);
//    public

}